<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class MyPromise {
            // 构造方法
            constructor(executor) {
                // 初始化值
                this.initValue()
                    // 初始化this指向
                this.initBind()
                    // 
                console.log('executor---', executor);
                executor(this.resolve, this.reject)
            }
            initBind() {
                // 初始化this
                this.resolve = this.resolve.bind(this)
                this.reject = this.reject.bind(this)
            }
            initValue() {
                // 初始化值
                this.PromiseResult = null // 终值
                this.PromiseState = 'pending' // 状态
            }
            resolve(value) {
                // 如果执行resolve，状态变为fulfilled
                this.PromiseState = 'fulfilled'
                    // 终值为传进来的值
                this.PromiseResult = value
            }
            reject(reason) {
                // 如果执行reject，状态变为rejected
                this.PromiseState = 'rejected'
                    // 终值为传进来的reason
                this.PromiseResult = reason
            }
        }

        const test1 = new MyPromise((resolve, reject) => {
            resolve('成功')
        })
        console.log('----', test1);
        const test2 = new MyPromise((resolve, reject) => {
            reject('失败')
        })
        console.log('----', test2);
    </script>
</body>

</html>